<?php

namespace app\controllers;


use app\components\AppController;
use app\models\Post;
use app\models\PostMeta;
use yii\db\ActiveQuery;

class SearchController extends AppController {

    public function actionIndex($id) {
        $model = new PostMeta();
        $model->with = ['post'];

        $dataProvider = $model->search(['type' => PostMeta::TYPE_TAG, 'name' => $id], TRUE);
        $models = $dataProvider->getModels();
        $pagination = $dataProvider->getPagination();

        foreach ($models as &$item) {
            if (isset($item['post'])) {
                $item = $item['post'];
            }
        }

        $this->view->title = $id;
        $this->keywords = $id;

        $view = '/video/index';
        return $this->render(compact('models', 'pagination'), $view);
    }
}